package com.cari.oa.domain;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.Length;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
* Title: SoftModuleEntity
* Description:软件模块
* Company: cari 
* @author  hjx 
* @date    2013-1-29
 */
@Entity
@Table(name = "T_SOFTMODULE")
public class SoftModuleEntity implements Serializable {

    private static final long serialVersionUID = 8775225809962095596L;

    @Id
    @Length(max = 32)
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    private String id;

    @NotNull(message = "名称不能为空")
    @Length(max = 100, message = "名称长度要小于100个字符")
    private String name;

    @Column(name = "pId")
    private String pId;

    @NotNull(message = "所属项目不能为空")
    @Length(max = 32, message = "所属项目名称长度不能超过32个字符")
    @Column(name = "PROJECT_ID")
    private String projectId;

    @Column(name = "status")
    private String status;	
    
	@Column(name = "create_time")
    private Date createTime = new Date();

	
	@Column(name = "DESCRIPTION")
    @Length(max = 1000, message = "描述长度要小于1000个字符")
	private String description;
	
	/**
     * 存储子模块
     */
    @Transient
	private List<SoftModuleEntity> children;
    
    /**
     * 父亲节点的名称
     */
    @Transient
    private String pName; 
    /**
     * 是否是子节点
     */
    @Transient
    private String isChild;
    
    public String toTreeString()
    {
    	StringBuffer sb = new StringBuffer();
    	if(children == null || children.size() == 0)  //顶级节点下没有子节点
    	{
    		sb.append("<li rel='"+this.id+"'> "+this.name+" </li>");
    	}else                                      
    	{
    		sb.append("<li rel='"+this.id+"'> "+this.name);
    		sb.append("<ul>");
    		for(SoftModuleEntity child : children)
    		{
    			sb.append(child.toTreeString());    		
    		}
    		sb.append("</ul></li>");
    	}
    	return sb.toString();
    }

    public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getpId() {
		return pId;
	}

	public void setpId(String pId) {
		this.pId = pId;
	}

	public String getProjectId() {
		return projectId;
	}

	public void setProjectId(String projectId) {
		this.projectId = projectId;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public List<SoftModuleEntity> getChildren() {
		return children;
	}

	public void setChildren(List<SoftModuleEntity> children) {
		this.children = children;
	}

	public String getpName() {
		return pName;
	}

	public void setpName(String pName) {
		this.pName = pName;
	}

	public String getIsChild() {
		return isChild;
	}

	public void setIsChild(String isChild) {
		this.isChild = isChild;
	}
}
